package Process2;

public class InterruptedResetFlag {

    public static void main(String[] args) {
//        test1();
        test2();
    }

    public static void test1(){
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                //标志位=true
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().isInterrupted());
                }
                //打印结果：10次true
            }
        });
        t.start();
        t.interrupt();//1,标志位=true
    }

    public static void test2(){
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                //标志位=true
                for (int i = 0; i < 10; i++) {
                    //i==0, 打印true，重置标志位=false
                    System.out.println(Thread.interrupted());
                }
                //打印结果：第一次true，后边9次false
            }
        });
        t.start();
        t.interrupt();//1,标志位=true
    }
}
